<?php
session_start();
require_once('models/Auth.class.php');	
require_once("configs/db_connect.php");
require_once("models/Advrets.class.php");
require_once('configs/common.php');

$link_id=safe_var($_GET['id']);

if (!Auth::isCheckSuccess())
{
	 try 
	{					
		 $template = $twig->loadTemplate('external_advert_view_no_auth.html');			 
		 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
		 
		 if (!is_numeric($link_id))
		 {
			 $data['adverts']=null;
		 }
		 else
		 {
			 $data['adverts']=Adverts::getAdvertById($link_id);
		 }
			 
		 echo $template->render($data);		
  
	} 
	catch (Exception $e) 
	{
		 die ('ERROR: ' . $e->getMessage());
	}
}
else
{
	  try 
	{					
		 $template = $twig->loadTemplate('external_advert_view.html');			 
		 $data=Translate::getPageKeys(KEYS_FILE."my_account.ini"); 
		 $data['adverts']=Adverts::getAdvertById($link_id);
			 
		 echo $template->render($data);		
  
	} 
	catch (Exception $e) 
	{
		 die ('ERROR: ' . $e->getMessage());
	}
}